package ExpressOne;

import javax.swing.*;
import java.awt.*;


public class MemoryDisplayForm extends JFrame {
    JButton []buttons;
    MemoryDisplayForm(int MaxSize){
        super("内存示意图");
        JPanel heap=new JPanel(new GridLayout(MaxSize/2,2));
        buttons=new JButton[MaxSize];
        for(JButton jButton:buttons){
            jButton=new JButton();
            jButton.setBackground(Color.green);
            heap.add(jButton);
        }

        add(heap);

        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setBounds(200,100,600,600);
        setVisible(true);
    }
    void setColor(int begin,int end,Color color){
        for(int i=begin;i<end;i++){
            buttons[i].setBackground(color);
        }
    }
}
